package com.spring.sys.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.spring.sys.dao.SysUserDicDao;
import com.spring.sys.dto.SysDicDto;
import com.spring.sys.po.SysDic;
import com.spring.sys.service.ISysDicService;

@Service
public class SysDicServiceImpl implements ISysDicService {

	@Autowired
	private SysUserDicDao sysUserDicDao;

	@Override
	public List<SysDicDto> findAllDictType() {
		// TODO Auto-generated method stub
		List<SysDic> list = sysUserDicDao.find("findAllDictType", null);
		List<SysDicDto> dtoList = new ArrayList<>();
		SysDicDto sdd = null;
		for (SysDic sysDic : list) {
			sdd = new SysDicDto(sysDic.getCode(), sysDic.getValue());
			dtoList.add(sdd);
		}
		return dtoList;

	}

	@Override
	public List<SysDic> findDictByParentCode(String code) {
		// TODO Auto-generated method stub
		return sysUserDicDao.find("findDictByParentCode", code);
	}

	@Override
	public void insert(SysDic sysDic) {
		// TODO Auto-generated method stub
		sysUserDicDao.insert(sysDic);
	}

	@Override
	public void update(SysDic sysDic) {
		// TODO Auto-generated method stub
		sysUserDicDao.update(sysDic);
	}

	@Override
	public void delete(Long id) {
		// TODO Auto-generated method stub
		sysUserDicDao.delete(id);
	}

	@Override
	public SysDic getSysDicByCode(SysDic sysDic) {
		return sysUserDicDao.get("getSysDicByCode", sysDic);
	}

	@Override
	public SysDic findByParentCodeAndCode(Long id, String parentCode, String code) {
		// TODO Auto-generated method stub
		Map<String,Object> map = new HashMap<>();
		map.put("id", id);
		map.put("parentCode", parentCode);
		map.put("code", code);
		return sysUserDicDao.get("findByParentCodeAndCode", map);
	}

}
